package com.wujunhao1024.sqldp.entity;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class Field {

    /**
     * 字段唯一标识
     */
    private String uuid;

    /**
     * 字段名称
     */
    private String fieldName;

    /**
     * 元素名称（涉及到 Function 的情况）
     */
    private String parameterName;

    /**
     * 字段别名
     */
    private String aliasName;

    /**
     * 字段所在表名
     */
    private String tableName;

    /**
     * 字段所在表别名
     */
    private String innerAliasTable;

    /**
     * 外部表别名
     */
    private String outerAliasTable;

    /**
     * 类型: <br/>
     * 0 - 默认值，不为 Function 组成部分 <br/>
     * 1 - 作为 Function 的参数 <br/>
     * 2 - 作为 *
     */
    private int type = 0;

    private List<Field> sourceFields = new ArrayList<>();

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public String getFieldName() {
        return fieldName;
    }

    public void setFieldName(String fieldName) {
        this.fieldName = fieldName;
    }

    public String getAliasName() {
        return aliasName;
    }

    public void setAliasName(String aliasName) {
        this.aliasName = aliasName;
    }

    public String getParameterName() {
        return parameterName;
    }

    public void setParameterName(String parameterName) {
        this.parameterName = parameterName;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public String getInnerAliasTable() {
        return innerAliasTable;
    }

    public void setInnerAliasTable(String innerAliasTable) {
        this.innerAliasTable = innerAliasTable;
    }

    public String getOuterAliasTable() {
        return outerAliasTable;
    }

    public void setOuterAliasTable(String outerAliasTable) {
        this.outerAliasTable = outerAliasTable;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public List<Field> getSourceFields() {
        return sourceFields;
    }

    public void addSource(Field field) {
        sourceFields.add(field);
    }

    public void addSource(List<Field> fields) {
        sourceFields.addAll(fields);
    }

    public Field() {
    }

    public Field(String fieldName, String aliasName, String tableName, String innerAliasTable, String outerAliasTable) {
        this.uuid = UUID.randomUUID().toString();
        this.fieldName = fieldName;
        this.aliasName = aliasName;
        this.tableName = tableName;
        this.innerAliasTable = innerAliasTable;
        this.outerAliasTable = outerAliasTable;
        this.type = 0;
    }

    public Field(String fieldName, String aliasName, String parameterName, String tableName, String innerAliasTable, String outerAliasTable) {
        this.uuid = UUID.randomUUID().toString();
        this.fieldName = fieldName;
        this.aliasName = aliasName;
        this.parameterName = parameterName;
        this.tableName = tableName;
        this.innerAliasTable = innerAliasTable;
        this.outerAliasTable = outerAliasTable;
        if (parameterName != null) {
            this.type = 1;
        } else {
            if (!"*".equals(fieldName)) {
                this.type = 0;
            } else {
                this.type = 2;
            }
        }
    }
}
